<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NewAutocomplete.aspx.cs"
    Inherits="Testing_NewAutocomplete" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

    <script type="text/javascript">
            // Hook up to the AutoComplete populating/populated events
            function pageLoad() {
                SetContext();
            }  
            
            function SetContext()
            {
            //alert('zxczx');
                var autoComplete = $find('AutoCompleteBehavior');
                //if (!autoComplete) return;
                var target = autoComplete.get_element();
                //if (!target) return;
                var userContext = $get('ddNewState');
                //if (!userContext) return;
                
                // Dynamically assign the context and change the color when processing
                autoComplete.add_populating(function()
                    {
                        autoComplete.set_contextKey(userContext.value);
                    });
                autoComplete.add_populated(function()
                    {
                       
                    });
            }
           
    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div>
            &nbsp;<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
            </ajaxToolkit:ToolkitScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                <ContentTemplate>
                    <asp:DropDownList ID="ddNewCountry" runat="server" AutoPostBack="True" DataSourceID="odsCountries"
                        DataTextField="CountryName" DataValueField="CountryID" OnSelectedIndexChanged="ddNewContactCountry_SelectedIndexChanged">
                    </asp:DropDownList><br />
                    <asp:DropDownList ID="ddNewState" runat="server"  DataSourceID="odsStates" DataTextField="DivisionName"
                        DataValueField="AdministrativeDivisionID" AutoPostBack="true">
                    </asp:DropDownList><br />
                    <asp:ObjectDataSource ID="odsStates" runat="server" OldValuesParameterFormatString="original_{0}"
                        SelectMethod="SelectAllWCountryID" TypeName="PlacementManager.Geo_AdministrativeDivisionComponent">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="ddNewCountry" Name="CountryID" PropertyName="SelectedValue"
                                Type="Int32" />
                            <asp:Parameter DefaultValue="DivisionName" Name="sortExpression" Type="String" />
                        </SelectParameters>
                    </asp:ObjectDataSource>
                    <asp:ObjectDataSource ID="odsCountries" runat="server" DeleteMethod="Delete" InsertMethod="Insert"
                        OldValuesParameterFormatString="original_{0}" SelectMethod="SelectAllWDisplay"
                        TypeName="PlacementManager.Geo_CountryComponent" UpdateMethod="Update">
                        <SelectParameters>
                            <asp:Parameter DefaultValue="CountryName" Name="sortExpression" Type="String" />
                        </SelectParameters>
                        <DeleteParameters>
                            <asp:Parameter Name="CountryID" Type="Int32" />
                        </DeleteParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="CountryID" Type="Int32" />
                            <asp:Parameter Name="CountryName" Type="String" />
                            <asp:Parameter Name="CountryCode" Type="String" />
                            <asp:Parameter Name="SubDivisionSingularName" Type="String" />
                            <asp:Parameter Name="SubDivisionPluralName" Type="String" />
                            <asp:Parameter Name="Display" Type="Boolean" />
                        </UpdateParameters>
                        <InsertParameters>
                            <asp:Parameter Name="CountryName" Type="String" />
                            <asp:Parameter Name="CountryCode" Type="String" />
                            <asp:Parameter Name="SubDivisionSingularName" Type="String" />
                            <asp:Parameter Name="SubDivisionPluralName" Type="String" />
                            <asp:Parameter Name="Display" Type="Boolean" />
                        </InsertParameters>
                    </asp:ObjectDataSource>
                    &nbsp;<br />
                    <asp:TextBox ID="txtNewCity" runat="server" AutoPostBack="True" Width="257px"></asp:TextBox>
                    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ContextKey="2"
                        ServiceMethod="GetLocationsForState" BehaviorID="AutoCompleteBehavior" ServicePath="~/WebServices/Geo_LocationService.asmx"
                        TargetControlID="txtNewCity" UseContextKey="True">
                    </ajaxToolkit:AutoCompleteExtender>
                    <ajaxToolkit:AnimationExtender ID="AnimationExtender1" runat="server" TargetControlID="txtNewCity" />
                </ContentTemplate>
            </asp:UpdatePanel>
        </div>
    </form>
</body>
</html>
